package com.panfeng.xcloud.boss.provider.member.init;

import com.panfeng.xcloud.boss.provider.member.dao.mapper.DataDictionaryMapperExt;
import com.panfeng.xcloud.common.core.configuration.DataDictionaryConfig;
import com.panfeng.xcloud.dao.member.entity.DataDictionary;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

@Component
@Order(Integer.MIN_VALUE)
public class LoadDataDictionaryConfigService {

    private final Logger logger = LoggerFactory.getLogger(LoadDataDictionaryConfigService.class);

    @Autowired
    private DataDictionaryMapperExt dataDictionaryMapperExt;

    @Autowired
    private DataDictionaryConfig config;

    @PostConstruct
    public void init() {
        logger.info("**********************start load dataDictionaryConfig info");
        List<DataDictionary> dataDictionaries = dataDictionaryMapperExt.queryAll();
        Map<String, String> codeToNameMap = config.getCodeToNameMap();
        for (DataDictionary dataDictionary : dataDictionaries) {
            codeToNameMap.put(dataDictionary.getCode(), dataDictionary.getName());
        }
        config.setCodeToNameMap(codeToNameMap);
        logger.info("**********************end load dataDictionaryConfig info");
    }

}
